const slime_core   = require("../../annotation/index.js");
const sources = @options("sources") || {};

@.async(async function () {
    await @promise("slime.ready");

    if (sources["phone"]) {

        slime_core.sources["phone"] = {
            owner : sources["phone"],
            detector : function (lab,session) {
                if (session.currentMember && session.currentMember.phone) {
                    return {
                        idValue : session.currentMember.phone
                    }
                }
            }
        }

    }

    if (sources["email"]) {

        slime_core.sources["email"] = {
            owner : sources["email"],
            detector : function (lab,session) {
                if (session.currentMember && session.currentMember.email) {
                    return {
                        idValue : session.currentMember.email
                    }
                }
            }
        }

    }
});

// TODO : phone => getMemberWithPhone => member 
/**
 * 
 * owner ouid 
 * (weixin == phone) {
 *     phone => getMemberWithPhone => member 
 *      member !== weixin.member
 *      weixin 为主去吞并phone的信息；
 * }
 */
//if (weixin -> phone => getMemberWithPhone)

module.exports = function (lab) {
    return {
        @registerWithPhone : function ({name, phone}) {
            // currentMember and currentMemberID => phone; source = phone;
        },
        @mergeWithPhone : function (targetMember, phone) {
            
        },
        @getMemberWithPhone : function (phone) {
            
        },
        @registerWithEmail : function ({name, phone}) {
            // currentMember and currentMemberID => phone; source = phone;
        },
        @mergeWithEmail : function (targetMember, phone) {
            
        },
        @getMemberWithEmail : function (phone) {
            
        }
    }
}